package com.crrc.dataparse.monitor.base.resource;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class MemoryResource implements IResource {
    private Object resource; // 存储单一资源对象

    private Map<Object, Object> resourceMap = new HashMap();

    public MemoryResource() {
    }

    public MemoryResource(Object resource) {
        this.resource = resource;
    }

    @Override
    public Object getResourceItem(Object key) {
        // 单一实例场景下无需key，直接返回资源
        return this.resource;
    }

    @Override
    public void addResourceItem(Object key, Object value) {
        // 单一实例直接赋值（忽略key）
        this.resource = value;
    }

    @Override
    public void deleteResourceItem(Object key) {
        // 清除单一资源
        this.resource = null;
    }

    @Override
    public void updateResourceItem(Object key, Object value) {
        // 更新单一资源（忽略key）
        this.resource = value;
    }

    @Override
    public Object getResource() {
        return this.resource;
    }

    @Override
    public Object getResourceKey(Object obj) {
        // 单一实例无key，返回null
        return null;
    }

    /**
     * 直接设置资源对象（替代原Map批量更新）
     */
    public void updateResource(Object value) {
        this.resource = value;
    }

    @Override
    public Set<String> getItemKeySet() {
        // 单一实例无key集合，返回null
        return null;
    }

    @Override
    public Map<String, String> getItemSet() {
        // 单一实例无键值对集合，返回null
        return null;
    }
    @Override
    public Object getResourceMapItem(Object key) {
        return this.resourceMap.get(key);
    }
    @Override
    public void addResourceMapItem(Object key, Object value) {
        this.resourceMap.put(key, value);
    }

    @Override
    public Object getResourceMap() {
        return this.resourceMap;
    }
}